package values.product
{
import core.Configuration;
import core.Language;

import framework.dao.EntryUtil;

import values.common.BonusValue;
import values.common.CostValue;
import values.item.IItemValue;
import values.item.INumbericItemValue;
import values.item.ItemTemplateValueList;
import values.item.ItemValue;

ProductPossiblePlusValue

/**
 * ProductTemplateValue
 * @author jliang
 *
 */
public class ProductTemplateValue
{
	[Data(type="field", mapping="@key")]
	public var key:String;
	
	[Data(type="field", mapping="@name")]
	public var baseNameKey:String;
	
	public function get name():String
	{
		return Language.getText(baseNameKey);
	}
	
	[Data(type="field", mapping="@desc")]
	public var baseDescKey:String;
	
	public function get desc():String
	{
		return Language.getText(baseDescKey);
	}
	
	[Data(type="field", mapping="@icon")]
	public var baseIconPath:String;
	
	public function get icon():String
	{
		return Configuration.assetsPath + baseIconPath;
	}
	
	[Data(type="field", mapping="time")]
	public var time:Number;
	
	[Data(type="field",  mapping="cost")]
	public var baseCostDef:*;
	
	protected var _cost:CostValue;
	
	public function get cost():CostValue
	{
		if (!_cost)
		{
			_cost = EntryUtil.mapping(baseCostDef, CostValue);
			_cost.owner = this;
		}
		return _cost;
	}
	
	[Data(type="field",  mapping="bonus")]
	public var baseBonusDef:*;
	
	protected var _bonus:BonusValue;
	
	public function get bonus():BonusValue
	{
		if (!_bonus)
		{
			_bonus = EntryUtil.mapping(baseBonusDef, BonusValue);
		}
		return _bonus;
	}
	
	protected var _mainProduct:INumbericItemValue;
	
	public function get mainProduct():INumbericItemValue
	{
		if (!_mainProduct)
		{
			for each (var obj:* in baseBonusDef.item)
			{
				if (int(obj.@index) == 1)
				{
					_mainProduct = ItemValue.create(ItemTemplateValueList.getByKey(String(obj.@key)), null, { num: Number(obj.@num) }) as INumbericItemValue;
					break;
				}
			}
		}
		return _mainProduct;
	}
	
	[Data(type="mapping", 
			   mapping="possible_plus.plus", 
			   ref="values.product.ProductPossiblePlusValue",
			   way="one_to_more")]
	public var possiblePlus:Array;
}
}





